<include file="Public/min-header" />
<style type="text/css">
	.olist ul{float:left;background:#eee;border:1px solid #000066; position:absolute}
	.olist li{list-style:none;width:256px;height:30px;line-height:30px;border-bottom:1px dashed #ccc;margin-left:-30px;text-align: center;}
	input{width: 90%;}
</style>
<div class="wrapper">
	<include file="Public/breadcrumb"/>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	             <div class="box-header">
	           	   <nav class="navbar navbar-default">	     
				      <div class="collapse navbar-collapse">
	    				<div class="navbar-form form-inline">
				            <div class="form-group">
				            	<p class="text-success margin blod">店铺管理:</p>
				            </div>
				             <div class="form-group">
				             <if condition="$is_own_shop eq 0">
                                 <a class="btn btn-default" href="{:U('Store/store_list')}">店铺列表</a>&nbsp;&nbsp;&nbsp;&nbsp;                                            
                                 <a class="btn btn-default" href="{:U('Store/apply_list')}" >开店申请</a>&nbsp;&nbsp;&nbsp;                                          
                                 <a class="btn btn-default" href="{:U('Store/reopen_list')}" >签约申请</a>&nbsp;&nbsp;&nbsp;
                             <else/>
                                 <a class="btn btn-default" href="{:U('Store/store_own_list')}">管理</a>&nbsp;&nbsp;&nbsp;&nbsp;
                                 <a class="btn btn-default" href="javascript:;" >新增</a>&nbsp;&nbsp;&nbsp;
                              </if>
				            </div>
	                        <div class="pull-right">
				                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
				            </div>
				          </div>
				       </div>
	    		 	</nav>	
	               	<nav class="navbar navbar-default">
		            	<if condition="$is_own_shop eq 1">
		            	<div class="callout callout-inro">
			            	<p>平台可以在此处添加自营店铺，新增的自营店铺默认为开启状态</p>
							<p>新增自营店铺默认绑定所有经营类目并且佣金为0，可以手动设置绑定其经营类目</p>
							<p>新增自营店铺将自动创建店主会员账号（用于登录网站会员中心）以及商家账号（用于登录商家中心）</p>
						</div>
						<else/>
						<div class="callout callout-inro">
							<p>1. 平台可以在此处添加外驻店铺，新增的外驻店铺默认为开启状态</p>
					        <p>2. 新增外驻店铺默认绑定所有经营类目并且佣金为0，可以手动设置绑定其经营类目。</p>
					        <p>3. 新增外驻店铺将自动创建店主会员账号（用于登录网站会员中心）以及商家账号（用于登录商家中心）。</p>
		            	</div>
						</if>
	    			</nav>
	             </div>
	             <div class="box-body">
	           	 <div class="row">
	            	<div class="col-sm-12">
	            	  <form method="post" id="store_info">
		              <table class="table table-bordered table-striped dataTable">
                        <tbody> 
                        <tr><td>店铺名称：</td>
                        	<td><input name="store_name" value="{$store.store_name}" onblur="store_check()"></td>
                        	<td>一个好记的店铺名称很重要！</td>
                        </tr>
                        <tr>
							<td style="color: red;">所属会员：</td>
                        	<td class="olist"><input type="text" name="user_name" id="user_name" value="{$store.user_name}" oninput="out_list()" onblur="store_check()"  autocomplete="off" placeholder='可以搜索姓名,手机检索'>
								<ul>
								</ul>
							</td>
                        	<td class="text-warning">选择会员绑定,支持手机或邮箱，一个会员只能绑定一个店铺！</td>
                        </tr>
                        <tr>
                            <td>店铺账号：</td>
                            <td>
								<input name="seller_name" id="seller_name" onblur="store_check()" value="{$store.seller_name}"> 
								</td>
                       		<td class="text-warning">用于登录商家后台账号</td>
                        </tr> 
                         <tr>
                            <td>登陆密码：</td>
                            <td><input type="text" name="password" value="{$store.password}"></td>
                       		<td class="text-warning">用于登陆商家后台密码为6-16位字母数字组合</td>
                        </tr> 
                        </tbody>
                        <tfoot>
                        <tr>
                        <td colspan="3" style="text-align:center;">
                        	<a href="javascript:void(0)" onclick="actsubmit()" class="btn btn-info margin">提交</a>
                        	<input type="hidden" name="is_own_shop" value="{$is_own_shop}">        
                        </td>
                        </tr>
                        </tfoot>
		               </table>
		               </form>
	               </div>
	            </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
<script>
var flag = true;
function actsubmit(){
	if($('input[name=store_name]').val() == ''){
		layer.msg("店铺名称不能为空", {icon: 2,time: 2000});
		return;
	}
	var user_name = $('input[name=user_name]').val();
	if(user_name == ''){
		layer.msg("所属会员账号不能为空", {icon: 2,time: 2000});
		return;
	}
	if(!checkEmail(user_name) && !checkMobile(user_name)){
		layer.msg("所属会员账号格式有误", {icon: 2,time: 2000});
		return;
	}
	if($('input[name=seller_name]').val() == ''){
		layer.msg("店铺账号不能为空", {icon: 2,time: 2000});
		return;
	}
	if($('input[name=password]').val() == ''){
		layer.msg("店铺登陆密码不能为空", {icon: 2,time: 2000});
		return;
	}
	if(flag){
		$('#store_info').submit();
	}
}

function store_check(){
	$.ajax({
		type:'post',
		url:"{:U('Store/store_check')}",
		dataType:'json',
		data:{store_name:$('input[name=store_name]').val(),seller_name:$('input[name=seller_name]').val(),user_name:$('input[name=user_name]').val()},
		success:function(res){
			if(res.stat != 'ok'){
				layer.msg(res.msg, {icon: 2,time: 2000});
				flag = false;
				return;
			}else{
				flag = true;
			}
		}
	});
}

function out_list(){
	var mytxt=$("#user_name").val();
	$.ajax({
		type:'post',
		url:"{:U('Store/out_list')}",
		dataType:'json',
		data:{key:mytxt},
		success:function(res){
			var olist=res.olist;
			var str='';
			for(var i=0;i<olist.length;i++){
				str+='<li rel="'+olist[i]['mobile']+'">'+olist[i]['nickname']+olist[i]['mobile']+'</li>';
			}
			$('.olist ul').html('');$('.olist ul').html(str);
		}
	});
}

$(".olist").on("click","li",function(){
	var myrel=$(this).attr('rel');
	$("#user_name").val(myrel);
	$('.olist ul').html('');
});

</script>
</div>
</body>
</html>   
